package Homework.Top2.SubjectDao;


import java.util.List;
import java.util.Scanner;

public class SubjectTest {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        SubjectDao dao=new SubjectDao();
        int choice;
        while (true){
            System.out.println("1:查看所有信息\t2：查找某一信息\t3：添加信息\t4：修改信息\t5：删除信息\t9：退出");
            choice=scanner.nextInt();
            switch (choice){
                case 1:
                    List<Subject> all = dao.searchAll();
                    for(Subject s:all)
                        System.out.println(s);
                    break;
                case 2:
                    System.out.println("input id:");
                    int id = scanner.nextInt();
                    Subject subject = dao.searchOne(id);
                    System.out.println(subject==null?"not found":subject);
                    break;
                case 3:
                    System.out.println("input subjectname:");
                    String subjectname = scanner.next();
                    System.out.println("input classhour:");
                    int classhour = scanner.nextInt();
                    System.out.println("input gradeid:");
                    int gradeid = scanner.nextInt();
                    Subject subject1 = new Subject();
                    subject1.setSubjectname(subjectname);
                    subject1.setClasshour(classhour);
                    subject1.setGradeid(gradeid);
                    int result = dao.add(subject1);
                    if (result!=-1){
                        System.out.println("succeed ,id:"+result);
                    }else {
                        System.out.println(" failed ");
                    }
                    break;
                case 4:
                    System.out.println("input id:");
                    int id1 = scanner.nextInt();
                    System.out.println("input new subjectname:");
                    String subjectname1 = scanner.next();
                    System.out.println("input new classhour:");
                    int classhour1 = scanner.nextInt();
                    System.out.println("input new gradeid:");
                    int gradeid1 = scanner.nextInt();
                    Subject subject2 = new Subject();
                    subject2.setId(id1);
                    subject2.setSubjectname(subjectname1);
                    subject2.setClasshour(classhour1);
                    subject2.setGradeid(gradeid1);
                    System.out.println("affected:"+dao.update(subject2));
                    break;
                case 5:
                    System.out.println("input id:");
                    int id2 = scanner.nextInt();
                    System.out.println("affected:"+dao.del(id2));
                    break;
                case 9:
                    System.exit(0);
                default:
                    System.out.println("default,input:");
                    break;
            }
        }
    }
}

